package net.zjitc.servlet;

import net.zjitc.dao.UserDao;
import net.zjitc.domain.User;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

import net.zjitc.service.UserService;
import org.apache.commons.dbutils.handlers.BeanHandler;

/**
 * Created by hasee on 2017/9/26.
 */
@WebServlet(name = "LoginServlet",urlPatterns = "/ls")
public class LoginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");

        String username = request.getParameter("username");
        String password = request.getParameter("password");
        System.out.println(username+"   "+password);
        PrintWriter out = response.getWriter();

        User user = new User();
        user.setUsername(username);
        user.setPassword(password);

        UserService userService = new UserService();
        int x = userService.login(user);
        if(x==1){
            response.sendRedirect("/homework/log/login.jsp");
        }
        if(x==2){
            response.sendRedirect("/homework/log/login.jsp");
        }
        if(x==3){
            response.sendRedirect("/homework/log/success.jsp");
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
